﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using IntoNails.Infrastructure.ViewModels;
using IntoNails.Infrastructure.Views;
using IntoNails.Models;
using IntoNails.Modules.UserManagement.Models;

namespace IntoNails.Modules.UserManagement.ViewModels
{
    public class UserInteractionDialogViewModel : GenericInteractionViewModel<User>, IHeaderInfoProvider<string>
    {
        #region Fields

        private string _headerInfo;
        private bool _isEditMode;

        private string _username;
        private string _password;
        private string _confirmedPassword;

        private UserType _selectedAuthority;
        private GenderType _selectedGender;

        #endregion

        public UserInteractionDialogViewModel()
        {
            ////this.AddProductLinkCommand = new DelegateCommand(this.OnAddProductLinkCommandExecuted);
            ////this.ProductLinkGridLoadedCallbackCommand = new DelegateCommand<Grid>(this.OnProductLinkGridLoaded);
        }

        #region Commands

        ////public ICommand AddProductLinkCommand { get; private set; }
        ////public ICommand ProductLinkGridLoadedCallbackCommand { get; private set; }

        #endregion

        #region Implementation of IHeaderInfoProvider<string>

        public string HeaderInfo
        {
            get { return this._headerInfo; }
            set
            {
                this._headerInfo = value;
                base.RaisePropertyChanged(() => HeaderInfo);
            }
        }

        #endregion

        #region Properties

        public bool IsEditMode
        {
            get { return this._isEditMode; }
            set
            {
                this._isEditMode = value;
                base.RaisePropertyChanged(() => IsEditMode);
            }
        }

        public string Username
        {
            get { return this._username; }
            set
            {
                this._username = value;
                base.RaisePropertyChanged(() => Username);
            }
        }

        public string Password
        {
            get { return this._password; }
            set
            {
                this._password = value;
                base.RaisePropertyChanged(() => Password);
            }
        }

        public string ConfirmedPassword
        {
            get { return this._confirmedPassword; }
            set
            {
                this._confirmedPassword = value;
                base.RaisePropertyChanged(() => ConfirmedPassword);
            }
        }

        public IEnumerable<UserType> AuthorityValues
        {
            get
            {
                return Enum.GetValues(typeof(UserType)).Cast<UserType>();
            }
        }

        public IEnumerable<GenderType> GenderValues
        {
            get
            {
                return Enum.GetValues(typeof(GenderType)).Cast<GenderType>();
            }
        }

        public UserType SelectedAuthority
        {
            get { return this._selectedAuthority; }
            set
            {
                this._selectedAuthority = this.InteractionEntity.Authority = value;
                base.RaisePropertyChanged(() => SelectedAuthority);
            }
        }

        public GenderType SelectedGender
        {
            get { return this._selectedGender; }
            set
            {
                this._selectedGender = this.InteractionEntity.Gender = value;
                base.RaisePropertyChanged(() => SelectedGender);
            }
        }

        #endregion

        public override void ViewInvoked(object parameter)
        {
            base.ViewInvoked(parameter);

            UserDataContext dataContext = parameter as UserDataContext;
            if (dataContext == null)
                throw new NullReferenceException("dataContext");

            this.SelectedAuthority = dataContext.Authority;
            this.SelectedGender = dataContext.Gender;
            this.IsEditMode = dataContext.IsEditMode;
            this.HeaderInfo = this.IsEditMode ? "Edit Employee" : "Add New Employee";
        }
    }
}
